package com.api.gbhg.heyulei.service.impl;

import com.api.gbhg.heyulei.dao.ReimbursementQueryDao;
import com.api.gbhg.heyulei.dao.impl.ReimbursementQueryDaoImpl;
import com.api.gbhg.heyulei.service.ReimbursementQueryService;
import com.api.gbhg.luoao.tool.ToolCURD;
import com.api.gbhg.luoao.utils.ReimbursementDao;
import com.google.common.base.Joiner;
import weaver.conn.RecordSet;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author hyl
 * @version 1.0
 * @date 2021/4/17 14:15
 */
public class ReimbursementQueryServiceImpl implements ReimbursementQueryService {

    private  ReimbursementQueryDao queryDao = new ReimbursementQueryDaoImpl();

    /**
     * 根据requestid查询该流程数据
     */
    /*
    @Override
    public Map<String,Object> workflowInfo(String requestId, Map<String,Object> map){
        //主表名
        String tableName = queryDao.tableName(requestId);

        //根据不同的表更改字段名
        String fieldName = "jbr";
        if (tableName.equals("formtable_main_30")){
            fieldName = "jbry";
        }

        String money = "sqbxjehj";
        if (tableName.equals("formtable_main_35")){
            money = "jlje";
        } else if (tableName.equals("formtable_main_34")){
            money = "bxwbjehj";
        }

        Map<String,Object> maps = new HashMap<>();
        //查询流程主表数据
        RecordSet primayTable = queryDao.getPrimayTable(tableName,requestId,fieldName);
        //查询主表数据
        while (primayTable.next()){

            int type = ReimbursementDao.getType(tableName);
            //操作类型
            maps.put("type1 ",type);
            maps.put("requestId",primayTable.getStringNoTrim("requestId"));
            //经办人
            maps.put("jbr",primayTable.getStringNoTrim(fieldName));
            //审核状态
            maps.put("lczt", ToolCURD.Processnode(primayTable.getStringNoTrim("requestId")));
            //申请日期
            maps.put("sqrq",primayTable.getStringNoTrim("sqrq"));
            //贷方金额
            maps.put("sqbxjehj",primayTable.getStringNoTrim(money));
            //流程编号
            maps.put("lcbh",primayTable.getStringNoTrim("lcbh"));
            //关联号
            maps.put("glh","");


            //YS10 缉私举报奖金报销
            if ("formtable_main_30".equals(tableName)){
                //预算来源
                List ysly = new ArrayList();
                //预算项目
                List ysxm = new ArrayList();

//                ysly.add(primayTable.getStringNoTrim("ysly"));
                ysxm.add(primayTable.getStringNoTrim("ysxm"));

                maps.put("ysly", Joiner.on(",").join((Iterable<?>) ysly));
                maps.put("ysxm", Joiner.on(",").join((Iterable<?>) ysxm));
                //收款人
                List skr = new ArrayList();

                skr.add(primayTable.getStringNoTrim("skr"));

                maps.put("skr",Joiner.on(",").join((Iterable<?>) skr));
            }

            // YS06 培训费报销
            if (tableName.equals("formtable_main_26")){
                List ysly = new ArrayList();//预算来源
                List ysxm = new ArrayList();//预算项目
                List bmjjzcfl = new ArrayList();//部门经济支出分类

//                if (primayTable.getStringNoTrim("ysly").isEmpty()){
//                    ysly.add(primayTable.getStringNoTrim("ysly"));
//                }
                ysxm.add(ReimbursementDao.getProjectname(primayTable.getStringNoTrim("ysxm")));
                bmjjzcfl.add(ReimbursementDao.getbmjjczfl(primayTable.getStringNoTrim("bmjjzcfl")));
                maps.put("bmjjzcfl",Joiner.on(",").join((Iterable<?>) bmjjzcfl));
                maps.put("ysly", Joiner.on(",").join((Iterable<?>) ysly));
                maps.put("ysxm", Joiner.on(",").join((Iterable<?>) ysxm));


            }

            //主表id
            String mainid = primayTable.getStringNoTrim("id");

            //不是流程 YS06 培训费报销,YS10 缉私举报奖金报销  进行查询
            if (!tableName.equals("formtable_main_26") && !tableName.equals("formtable_main_30")){

                //查询明细表1
                RecordSet Detail1 = ReimbursementDao.getDetail1(tableName, mainid);

                List ysly = new ArrayList();//预算来源
                List ysxm = new ArrayList();//预算项目
                List bmjjzcfl = new ArrayList();//部门经济支出分类
                while (Detail1.next()){
//                    if (primayTable.getStringNoTrim("ysly").isEmpty()){
//                        ysly.add(primayTable.getStringNoTrim("ysly"));
//                    }
                    ysxm.add(ReimbursementDao.getProjectname(Detail1.getStringNoTrim("ysxm")));
                    bmjjzcfl.add(ReimbursementDao.getbmjjczfl(Detail1.getStringNoTrim("bmjjzcfl")));
                }

                maps.put("bmjjzcfl", Joiner.on(",").join((Iterable<?>) bmjjzcfl));
                maps.put("ysly", Joiner.on(",").join((Iterable<?>) ysly));
                maps.put("ysxm", Joiner.on(",").join((Iterable<?>) ysxm));

            }

            //不是流程 YS10 缉私举报奖金报销 进行查询
            if (!tableName.equals("formtable_main_30")) {

                //查询明细表2
                RecordSet detail2 = ReimbursementDao.getDetail2(tableName, mainid);

                List skr = new ArrayList();//收款人
                while (detail2.next()){
                    skr.add(detail2.getStringNoTrim("skr"));
                }
                maps.put("skr",Joiner.on(",").join((Iterable<?>) skr));

            }
        }


        return maps;
    }
*/
}
